﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NETMovie.BLL;
using System.Data;

namespace NETMovie.UI.Web.Reports
{
    public partial class TransactionSearch : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void imgStartDate_Click(object sender, ImageClickEventArgs e)
        {
            calStartDate.Visible = !calStartDate.Visible;
        }

        protected void imgEndDate_Click(object sender, ImageClickEventArgs e)
        {
            calEndDate.Visible = !calEndDate.Visible;
        }

        protected void calStartDate_SelectionChanged(object sender, EventArgs e)
        {
            txtStartDate.Text = String.Format("{0:dd MMM yyyy}", calStartDate.SelectedDate);
        }

        protected void calEndDate_SelectionChanged(object sender, EventArgs e)
        {
            txtEndDate.Text = String.Format("{0:dd MMM yyyy}", calEndDate.SelectedDate);
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            TransactionService service = new TransactionService();
            
            DateTime startDate = DateTime.MinValue;
            DateTime endDate = DateTime.MaxValue;

            try
            {
                startDate = Convert.ToDateTime(txtStartDate.Text);
            }
            catch
            {
                startDate = DateTime.MinValue;
            }

            try
            {
                endDate = Convert.ToDateTime(txtEndDate.Text);
            }
            catch
            {
                endDate = DateTime.MaxValue;
            }

            DataTable table = service.GetProfitableUsers(String.Empty, startDate, endDate);
            Session["TableData"] = table;

            Server.Transfer("~/Reports/SearchResults.aspx");
        }
    }
}